package com.cdshangpai.utils.offlinecache.account;

import com.cdshangpai.utils.api.Api;
import com.cdshangpai.utils.db.beans.Account;
import com.cdshangpai.utils.offlinecache.DbVersion;
import com.cdshangpai.utils.offlinecache.base.BaseCacheProcessor;
import com.cdshangpai.utils.offlinecache.base.DataDownloader;
import com.cdshangpai.utils.offlinecache.base.query.AccountQuery;

import java.util.List;

public class AccountCacheProcessor {
    AccountQuery accountQuery;
    Api api;

    public AccountCacheProcessor()
    {
        accountQuery=new AccountQuery();
        api=new Api();
    }

    public boolean begin(List<DbVersion> serverAccountVersions)
    {
        DataDownloader dataDownloader=new DataDownloader() {
            @Override
            public List download(List ids) {
                return api.queryAccount(ids);
            }
        };
        List<Account> localDatas=accountQuery.query();
        return new BaseCacheProcessor<Account>()
                .setDbQuery(accountQuery)
                .setDataDownloader(dataDownloader)
                .setLocalDatas(localDatas)
                .setServerVersion(serverAccountVersions)
                .forAccount()
                .begin();
    }
}
